package com.example.demo.utils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * TODO
 * 封装返回结果 (包含数据)
 * @author caiyonglan
 * @email 627064518@qq.com
 * @date 2020/12/2 15:07
 */
@Getter
@Setter
public class ResponseData extends Response {

    @ApiModelProperty(value = "响应数据")
    private Object data;

    public static ResponseData success(ExceptionMsg exceptionMsg, Object data) {
        ResponseData response = new ResponseData();
        response.setCode(exceptionMsg.getCode());
        response.setMsg(exceptionMsg.getMsg());
        response.setData(data);
        return response;
    }

    public static ResponseData error(ExceptionMsg exceptionMsg, Object data) {
        ResponseData response = new ResponseData();
        response.setCode(exceptionMsg.getCode());
        response.setMsg(exceptionMsg.getMsg());
        response.setData(data);
        return response;
    }

    public static ResponseData error(ExceptionMsg exceptionMsg) {
        ResponseData response = new ResponseData();
        response.setCode(exceptionMsg.getCode());
        response.setMsg(exceptionMsg.getMsg());
        return response;
    }


}
